#!/bin/zsh -Ndefgku
#
# Scripts/prebuild
# mas
#
# Copyright © 2025 mas-cli. All rights reserved.
#
# Prebuilds the Swift package.
#

. "${0:A:h}/_setup_script"

print_notice '🎬 Prebuilding' "${@}"

# Generate Swift file containing build information.
# shellcheck disable=SC1102
printf $'//
// MAS+BuildInformation.swift
// mas
//
// Copyright © $(date '\''+%%Y'\'') mas-cli. All rights reserved.
//

extension MAS {
	static let version = "%s"
	static let installMethod = "%s"
	static let gitOrigin = "%s"
	static let gitRevision = "%s"
	static let swiftVersion = "%s"
	static let swiftDriverVersion = "%s"
}
'\
 "$(Scripts/version)"\
 "${MAS_INSTALL_METHOD:-unknown}"\
 "$(git remote get-url origin)"\
 "$(git rev-parse HEAD)"\
 "$(printf %s "${${$(swift --version 2>/dev/null)#Apple Swift version }%%$'\n'*}")"\
 "$(printf %s "${${$((swift --version 3>&2 2>&1 1>&3) 2>/dev/null)#swift-driver version: }% }")"\
 >"${1}/MAS+BuildInformation.swift"
